﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using BCCommon;
using BCDto.Common.Banner;
using BCService.Common.Banner;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace BCTMSRESTful.Controllers.Management.Common.Banner
{
    /// <summary>
    /// Banner分类编码信息控制器
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class BannerTagcodeController : ManagementBaseController
    {
        private readonly IBannerTagcodeService bannerTagcodeService;

        public BannerTagcodeController(IBannerTagcodeService bannerTagcodeService)
        {
            this.bannerTagcodeService = bannerTagcodeService;
        }

        /// <summary>
        /// 创建Banner分类编码信息。
        /// </summary>
        /// <param name="dto">Banner分类编码信息</param>
        /// <response code="201">已成功添加Banner分类编码信息。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加Banner分类编码")]
        [ProducesResponseType(typeof(BannerTagcodeDto), 200)]
        public IActionResult Post([FromBody]BannerTagcodeRequestDto dto)
        {
            BannerTagcodeDto result = this.bannerTagcodeService.Add(dto);
            return this.Created(string.Format("/api/v1/sim/BannerTagcode/{0}", result.BannerTagcode), result);
        }

        /// <summary>
        /// 修改Banner分类编码信息。
        /// </summary>
        /// <param name="dto">Banner分类编码信息</param>
        /// <response code="200">返回修改成功的Banner分类编码信息。</response>
        /// <returns></returns>
        [HttpPut]
        [Log("修改Banner分类编码")]
        [ProducesResponseType(typeof(BannerTagcodeDto), 200)]
        public IActionResult Put([FromBody]BannerTagcodeRequestDto dto)
        {
            return this.Ok(this.bannerTagcodeService.Update(dto));
        }

        /// <summary>
        /// 获取Banner分类编码信息列表。
        /// </summary>
        /// <response code="200">返回Banner分类编码信息列表</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<BannerTagcodeDto>), 200)]
        public IActionResult GetList()
        {
            return this.Ok(this.bannerTagcodeService.GetList());
        }

        /// <summary>
        /// 获取Banner分类编码信息列表（分页）。
        /// </summary>
        /// <param name="tagCode">标记码</param>
        /// <param name="ascending">排序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">每页数据条数</param>
        /// <response code="200">返回Banner分类编码信息列表（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<BannerTagcodeDto>), 200)]
        public IActionResult Query([FromQuery(Name = "tag_code")]string tagCode,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return this.Ok(this.bannerTagcodeService.GetPageableList(tagCode, ascending, index, size));
        }
        /// <summary>
        /// 获取Banner分类编码信息。
        /// </summary>
        /// <response code="200">返回Banner分类编码信息</response>
        /// <returns></returns>
        [HttpGet("{banner_tagcode}")]
        [ProducesResponseType(typeof(BannerTagcodeDto), 200)]
        public IActionResult GetPageableList([FromRoute(Name = "banner_tagcode")]string bannerTagcode)
        {
            return this.Ok(this.bannerTagcodeService.Get(bannerTagcode));
        }

        /// <summary>
        /// 删除Banner分类编码信息。
        /// </summary>
        /// <param name="bannerTagcode">Banner分类编码</param>
        /// <response code="204">删除成功</response>
        /// <returns></returns>
        [HttpDelete("{banner_tagcode}")]
        [Log("删除Banner分类编码")]
        public IActionResult Delete([FromRoute(Name = "banner_tagcode")]string bannerTagcode)
        {
            this.bannerTagcodeService.Delete(bannerTagcode);
            return this.NoContent();
        }

        #region 启用/禁用Banner分类编码
        /// <summary>
        ///  启用/禁用Banner分类编码
        /// </summary>
        /// <param name="bannerTagcode">Banner分类编码</param>
        /// <param name="enabled">是否启用</param>
        /// <response code="204">启用/禁用Banner分类编码成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("[action]/{banner_tagcode}/{enabled}")]
        [Log("启用/禁用Banner分类编码")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Enabled([FromRoute(Name = "banner_tagcode")]string bannerTagcode,
            [FromRoute(Name = "enabled")]bool enabled)
        {
            if (enabled)
            {
                this.bannerTagcodeService.Enabled(bannerTagcode);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
            else
            {
                this.bannerTagcodeService.Disabled(bannerTagcode);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
        }
        #endregion
    }
}
